import { useConfigStore } from "@/store/modules/config";
import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from "vue-router";
import {useBreadcrumbStore} from "@/store/modules/breadcrumb";

// 获取模块路由信息
const modulesFiles: any = import.meta.glob("./modules/*.ts", { eager: true });
let modulesRouter: RouteRecordRaw[] = []
Object.keys(modulesFiles).forEach(key => {
    modulesRouter.push(...modulesFiles[key].default)
})

const router = createRouter({
    history: createWebHashHistory(),
    routes: [{
        path: "/",
        component: () => import("@/layout/index"),
        redirect: "/HomePage",
        children: [
            ...modulesRouter
        ]
    },
    {
        path: '/:w+',
        component: () => import("@/components/error/error_404")
    }]
})

router.beforeEach((route, from, next) => {
    // 返回首页，预约挂号的面包屑选择信息清空
    let breadcrumbStore = useBreadcrumbStore(); // 实例化Pinia存储
    if(route.path === '/HomePage'){
        breadcrumbStore.clearTitleArray()
    }

    if (route.meta.title) {
        /** 修改标题 */
        document.title = route.meta.title as string
    }
    next();
})

router.afterEach((route) => {

})

export default router;


